'use strict'

const stream = require('stream')

class BaseStream extends stream.Duplex {
    constructor(opts) {
        super(opts)
        this._buffer = []
        this.writableFinished
        this.counter = 0
    }
    _write(chunk, encoding, callback) {
        this._buffer.push(chunk)
      
        callback()

    }

    _read(size) {
        this.counter++
        console.log('Buf len:',this._buffer.length)
        while(this._buffer.length){
            let r
            this.push(r=this._buffer.shift())
            return r
        }
        if (this.writableFinished || this.writableEnded) {
            this.push(null)
        }
        return false
    }
}

module.exports = BaseStream